package com.ele.Servlet;

import com.ele.Pojo.FoodCategory;
import com.ele.Service.FoodCategoryService;
import com.ele.Service.impl.FoodCategoryServiceImpl;
import com.google.gson.Gson;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/findAllFoodCategory")
public class FindAllFoodCategoryServlet extends HttpServlet {
    private FoodCategoryService foodCategoryService = new FoodCategoryServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String shopId = req.getParameter("shopId");

        List<FoodCategory> list = this.foodCategoryService.findAllFoodCategory(shopId);
        // 将对象转成json
        String json = new Gson().toJson(list);
        resp.setContentType("application/json;charset=utf-8");
        resp.getWriter().write(json);
    }
}
